package com.serverTechnology.craft.controller;


import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import com.serverTechnology.craft.entity.dto.StepsResourceInsertDto;
import com.serverTechnology.craft.entity.vo.StandInfoVo;
import com.serverTechnology.craft.entity.vo.StandardVo;
import com.serverTechnology.craft.service.StepsResourceTypeService;
import com.serverTechnology.resource.service.IManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;

/**
 * <p>
 * 工步所需资源类型 前端控制器
 * </p>
 *
 * @author 王烁
 * @since 2024-08-01
 */
@Api(tags = "工艺管理")
@RestController
@RequestMapping("/stepsResourceType")
public class StepsResourceTypeController {

    @Autowired
    private StepsResourceTypeService stepsResourceTypeService;

    /**
     * 查询是否为非标设备 0是标准 1不是
     *
     * @param standard 根据是否为标准
     * @return List<StandardVo> id和名称
     */
    @ApiOperation(value = "查询是否为非标设备 0是标准 1不是")
    @GetMapping("/isStandard")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "standard", value = "0是标准 1不是", dataType = "Long", required = false),
    })
    public ResponseData<List<StandardVo>> isStandard(@RequestParam("standard") Long standard) {
        List<StandardVo> nonStandard = stepsResourceTypeService.isNonStandard(standard);
        return new SuccessResponseData<>(nonStandard);
    }

    /**
     * 工装、工具所需要的下拉框
     *
     * @param deviceDistinguish 设备EQUIPMENT，工具TOOL，工装FROCK
     * @return 设备、工装、工具名称和id
     */
    @ApiOperation(value = "工装、工具所需要的下拉框")
    @GetMapping("/getStepsDeviceDistinguish")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "deviceDistinguish", value = "设备EQUIPMENT，工具TOOL，工装FROCK", dataType = "String", required = false),
    })
    public ResponseData<List<StandardVo>> getStepsDeviceDistinguish(String deviceDistinguish) {
        List<StandardVo> stepsDeviceDistinguish = stepsResourceTypeService.getStepsDeviceDistinguish(deviceDistinguish);
        return new SuccessResponseData<>(stepsDeviceDistinguish);
    }

    /***
     *  添加所需标准、非标设备、工装、工具
     * @param stepsResourceInsertDto 标准、非标设备、工装、工具
     * @return
     */
    @ApiOperation(value = "添加所需标准、非标设备、工装、工具")
    @PostMapping("insertStepsResource")
    public ResponseData<StepsResourceInsertDto> insertStepsResource(@RequestBody StepsResourceInsertDto stepsResourceInsertDto) {
        stepsResourceTypeService.insertStepsResource(stepsResourceInsertDto);
        return new SuccessResponseData<>();
    }

    /***
     * 删除所需标准、非标设备、工装、工具
     * @param id
     * @return
     */
    @ApiOperation(value = "删除所需标准、非标设备、工装、工具")
    @PostMapping("deleteStepsResource")
    public ResponseData<StepsResourceInsertDto> deleteStepsResource(Long id) {
        stepsResourceTypeService.deleteStepsResource(id);
        return new SuccessResponseData<>();
    }

    /**
     * 查询工装、工具
     * @param id 工序id
     * @return List<StandInfoVo>
     */
    @ApiOperation(value = "回显、非标设备、标准设备、工装、工具")
    @GetMapping("/getStepsResource")
    public ResponseData<List<StandInfoVo>> getStepsResource(@RequestParam("id") Long id) {
       List<StandInfoVo>  stepsResource = stepsResourceTypeService.getStepsResource(id);
        return new SuccessResponseData<>(stepsResource);
    }
    /**
     * 查询 非标设备和准备设备
     * @param id 工序id
     * @return List<StandInfoVo>
     */
    @ApiOperation(value = "查询 非标设备和准备设备")
    @GetMapping("/getStepsEquipment")
    public ResponseData<List<StandInfoVo>> getStepsEquipment(@RequestParam("id") Long id) {
        List<StandInfoVo>  stepsResource = stepsResourceTypeService.getStepsEquipment(id);
        return new SuccessResponseData<>(stepsResource);
    }

}
